//bench.js 
const app = getApp()
const util = require('../../../utils/util.js')
var BLELocker = require("../../../utils/BLELocker.js");
var blueConStatHandler = require("../../../utils/blueConStatHandler.js");
const lbbService = require('../../../pages/service/service.js');


Page({
  data: {
    openning_show: false,
    isShow: true,
    loading_show: false,
    storeDetail: 0,
    hospitalId: '',
    activeTab: '0',
    newConFlg: true, //使用新连接
    hospitalInfo: {},
    isConnecting: false,
    modal_show: {
      modal_show: false,
      confirm: false,
      retryConnect: false,
      retry95: false,
    },
    chairPileStatus: [{
      value: '1',
      name: '低电桩',
      checked: false,
      color: 'color-r'
    },
    {
      value: '2',
      name: '维护中',
      checked: false,
      color: 'color-r'
    },
    {
      value: '4',
      name: '蓝牙连不上',
      checked: false,
      color: 'color-r'
    },
    {
      value: '14',
      name: '租借rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '5',
      name: '归还rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '6',
      name: '插入开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '7',
      name: '锁钩开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '10',
      name: '弹不开',
      checked: false,
      color: 'color-r'
    },
    {
      value: '12',
      name: '丢轮椅',
      checked: false,
      color: 'color-b'
    },
    {
      value: '3',
      name: '待升级',
      checked: false,
      color: 'color-r'
    },
    {
      value: '13',
      name: '待换锂电池',
      checked: false,
      color: 'color-b'
    },
    {
      value: '8',
      name: '欧姆龙开关',
      checked: false,
      color: 'color-b'
    },
    {
      value: '9',
      name: '轻弹簧',
      checked: false,
      color: 'color-b'
    },
    {
      value: '11',
      name: '复位电容',
      checked: false,
      color: 'color-b'
    },
    {
      value: '15',
      name: '未开锁巡检',
      checked: false,
      color: 'color-r'
    },
    {
      value: '16',
      name: '马达故障',
      checked: false,
      color: 'color-r'
    },
    {
      value: '17',
      name: '更换电池',
      checked: false,
      color: 'color-r'
    },
    {
      value: '18',
      name: '未上线',
      checked: false,
      color: 'color-r'
    },
    {
        value: '20',
        name: '近7日未巡检',
        checked: false,
        color: 'color-r'
    },
    ],
    chairPileStatusValue: 0,
    otherPileStatus: [{
      value: '1',
      name: '低电桩',
      checked: false,
      color: 'color-r'
    },
    {
      value: '2',
      name: '维护中',
      checked: false,
      color: 'color-r'
    },
    {
      value: '4',
      name: '蓝牙连不上',
      checked: false,
      color: 'color-r'
    },
    {
      value: '14',
      name: '租借rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '5',
      name: '归还rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '6',
      name: '插入开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '7',
      name: '锁钩开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '10',
      name: '弹不开',
      checked: false,
      color: 'color-r'
    },
    {
      value: '12',
      name: '丢轮椅',
      checked: false,
      color: 'color-b'
    },
    {
      value: '3',
      name: '待升级',
      checked: false,
      color: 'color-r'
    },
    {
      value: '13',
      name: '待换锂电池',
      checked: false,
      color: 'color-b'
    },
    {
      value: '8',
      name: '欧姆龙开关',
      checked: false,
      color: 'color-b'
    },
    {
      value: '9',
      name: '轻弹簧',
      checked: false,
      color: 'color-b'
    },
    {
      value: '11',
      name: '复位电容',
      checked: false,
      color: 'color-b'
    },
    {
      value: '15',
      name: '未开锁巡检',
      checked: false,
      color: 'color-r'
    },
    {
      value: '16',
      name: '马达故障',
      checked: false,
      color: 'color-r'
    },
    {
      value: '17',
      name: '48H未上线',
      checked: false,
      color: 'color-r'
    },
    {
      value: '18',
      name: '五天内重试3次上线',
      checked: false,
      color: 'color-r'
    },
    {
      value: '19',
      name: '未上线',
      checked: false,
      color: 'color-r'
    },
    {
        value: '20',
        name: '近7日未巡检',
        checked: false,
        color: 'color-r'
      },
    ],
    otherPileStatusValue: 0,
    carPileStatus: [{
      value: '1',
      name: '低电桩',
      checked: false,
      color: 'color-r'
    },
    {
      value: '2',
      name: '维护中',
      checked: false,
      color: 'color-r'
    },
    {
      value: '4',
      name: '蓝牙连不上',
      checked: false,
      color: 'color-r'
    },
    {
      value: '14',
      name: '租借rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '5',
      name: '归还rfid不识别',
      checked: false,
      color: 'color-r'
    },
    {
      value: '6',
      name: '插入开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '7',
      name: '锁钩开关',
      checked: false,
      color: 'color-r'
    },
    {
      value: '10',
      name: '弹不开',
      checked: false,
      color: 'color-r'
    },
    {
      value: '3',
      name: '待升级',
      checked: false,
      color: 'color-r'
    },
    {
      value: '13',
      name: '待换锂电池',
      checked: false,
      color: 'color-b'
    },
    {
      value: '8',
      name: '欧姆龙开关',
      checked: false,
      color: 'color-b'
    },
    {
      value: '9',
      name: '轻弹簧',
      checked: false,
      color: 'color-b'
    },
    {
      value: '11',
      name: '复位电容',
      checked: false,
      color: 'color-b'
    },
    {
      value: '15',
      name: '未开锁巡检',
      checked: false,
      color: 'color-r'
    },
    {
      value: '20',
      name: '近7日未巡检',
      checked: false,
      color: 'color-r'
    },
    ],
    carPileStatusValue: 0,
    chairStatus: [{
      value: '7',
      name: '本院到外院',
      checked: false,
      color: 'color-r'
    },
    {
      value: '2',
      name: '3天未租借',
      checked: false,
      color: 'color-r'
    },
    {
      value: '3',
      name: '维护中',
      checked: false,
      color: 'color-r'
    },
    {
      value: '1',
      name: '外院到本院',
      checked: false,
      color: 'color-r'
    },
    {
      value: '4',
      name: '疑似丢失',
      checked: false,
      color: 'color-r'
    },
    {
      value: '5',
      name: '使用中',
      checked: false,
      color: 'color-b'
    },
    {
      value: '6',
      name: '在桩上',
      checked: false,
      color: 'color-b'
    },
    {
      value: '8',
      name: '人工归还',
      checked: false,
      color: 'color-b'
    },
    {
      value: '9',
      name: '未支付赔偿',
      checked: false,
      color: 'color-b'
    },
    {
      value: '10',
      name: '未巡检轮椅',
      checked: false,
      color: 'color-r'
    },
    {
        value: '20',
        name: '近7日未巡检',
        checked: false,
        color: 'color-r'
      },
    ],
    otherEquStatus: [{
      value: '7',
      name: '本院到外院',
      checked: false,
      color: 'color-r'
    },
    {
      value: '2',
      name: '3天未租借',
      checked: false,
      color: 'color-r'
    },
    {
      value: '3',
      name: '维护中',
      checked: false,
      color: 'color-r'
    },
    {
      value: '1',
      name: '外院到本院',
      checked: false,
      color: 'color-r'
    },
    {
      value: '4',
      name: '疑似丢失',
      checked: false,
      color: 'color-r'
    },
    {
      value: '5',
      name: '使用中',
      checked: false,
      color: 'color-b'
    },
    {
      value: '6',
      name: '在桩上',
      checked: false,
      color: 'color-b'
    },
    {
      value: '8',
      name: '人工归还',
      checked: false,
      color: 'color-b'
    },
    {
      value: '9',
      name: '未支付赔偿',
      checked: false,
      color: 'color-b'
    },
    {
      value: '10',
      name: '未巡检轮椅',
      checked: false,
      color: 'color-r'
    },
    {
        value: '20',
        name: '近7日未巡检',
        checked: false,
        color: 'color-r'
    },
    ],
    chairStatusValue: 0,
    otherEquStatusValue:0,
    carStatus: [
      {
        value: '2',
        name: '3天未租借',
        checked: false
      },
      {
        value: '3',
        name: '维护中',
        checked: false
      },
      {
        value: '4',
        name: '疑似丢失',
        checked: false
      },
      {
        value: '5',
        name: '使用中',
        checked: false
      },
      {
        value: '6',
        name: '在桩上',
        checked: false
      },
      {
        value: '9',
        name: '未支付赔偿',
        checked: false
      },
      {
        value: '20',
        name: '近7日未巡检',
        checked: false,
        color: 'color-r'
      },
    ],
    carStatusValue: 0,
    list: [{
      name: '四角拐杖',
      value: 7,
      phcCarNum: 21,
    },
    {
      name: '五角拐杖',
      value: 8,
      phcCarNum: 31,
    },
    {
      name: '六角拐杖',
      value: 9,
      phcCarNum: 11,
    }
    ],
    infoTable:[
        
    ]
  },
  toggleTab: function (e) {
    let activeTab = e.currentTarget.dataset.activenum
    console.log(e)
    this.setData({
      activeTab: activeTab
    })
  },
  sortPile: function (a, b) {
    return a - b
  },
  clearRadio: function (num, equipList) {
    let that = this
    let activeTab = parseInt(num)
    if (activeTab == 0) {
      let chairPileStatus = that.data.chairPileStatus
      chairPileStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab0_event = null
      that.setData({
        chairPileStatus: chairPileStatus,
        chairPileStatusValue: 0
      })
      that.setData({
        pileChairListNew: equipList
      })
    } else if (activeTab == 2) {
      let carPileStatus = that.data.carPileStatus
      carPileStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab2_event = null
      that.setData({
        carPileStatus: carPileStatus,
        carPileStatusValue: 0
      })
      that.setData({
        pileStretchListNew: equipList
      })
    } else if (activeTab == 1) {
      let chairStatus = that.data.chairStatus
      chairStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab1_event = null
      that.setData({
        chairStatus: chairStatus,
        chairStatusValue: 0
      })
      that.setData({
        chairListNew: equipList
      })
    } else if (activeTab == 3) {
      let carStatus = that.data.carStatus
      carStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab3_event = null
      that.setData({
        carStatus: carStatus,
        chairStatusValue: 0
      })
      that.setData({
        carListNew: equipList
      })
    } else if (activeTab == 10) {
      console.log("---->>>>>>>>>>>>>>>>>>>>其他控制盒桩位");
      let otherPileStatus = that.data.otherPileStatus
      otherPileStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab10_event = null
      that.setData({
        otherPileStatus: otherPileStatus,
        otherPileStatusValue: 0
      })
      that.setData({
        pileOtherNewList: equipList
      })
    }else if(activeTab == 11) {      
      let otherEquStatus = that.data.otherEquStatus
      otherEquStatus.forEach(item => {
        item.checked = false
      })
      that.data.tab11_event = null
      that.setData({
        otherEquStatus: otherEquStatus,
        otherEquStatusValue: 0
      })
      that.setOtherEquipmentList(equipList);
    }
  },
  // 复制功能
  copyText: function (e) {
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
  setRadio: function (num, value, tem) {
    let that = this
    let activeTab = parseInt(num)
    if (activeTab == 0) {
      let chairPileStatus = that.data.chairPileStatus
      let pileList = that.data.hospitalInfo.pileChairList
      chairPileStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })
      that.setData({
        chairPileStatus: chairPileStatus,
        chairPileStatusValue: value,
        pileChairListNew: tem
      })
    } else if (activeTab == 2) {
      let carPileStatus = that.data.carPileStatus
      let pileList = that.data.hospitalInfo.pileChairList
      carPileStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })
      that.setData({
        carPileStatus: carPileStatus,
        carPileStatusValue: value,
        pileStretchListNew: tem
      })
    } else if (activeTab == 1) {
      let chairStatus = that.data.chairStatus
      chairStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })
      that.setData({
        chairStatus: chairStatus,
        chairStatusValue: value,
        chairListNew: tem
      })
    } else if (activeTab == 3) {
      let carStatus = that.data.carStatus
      carStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })
      that.setData({
        carStatus: carStatus,
        carStatusValue: value,
        carListNew: tem
      })
    }else if (activeTab == 10) {
      let otherPileStatus = that.data.otherPileStatus
      otherPileStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })
      that.setData({
        otherPileStatus: otherPileStatus,
        otherPileStatusValue: value,
        pileOtherNewList: tem
      })
    }else if(activeTab == 11) {
      //其他设备信息
      let otherEquStatus = that.data.otherEquStatus
      otherEquStatus.forEach(item => {
        if (item.value == value) {
          item.checked = true
        } else {
          item.checked = false
        }
      })

      that.setData({
        otherEquStatus: otherEquStatus,
        otherEquStatusValue: value
      });
      that.setOtherEquipmentList(tem);
    }
  },
  toHospitalDetailInfo: function () {
    wx.navigateTo({
      url: '/pages/hospitalDetailInfo/hospitalDetailInfo?hospitalInfo=' + JSON.stringify(this.data.hospitalInfo.basicInfo) + '&hospitalId=' + this.data.hospitalId,
    })
  },
  // 轮椅桩筛选
  pileChairChange: function (e) {
    let that = this
    console.log("pileChairChange-->", e);
    let value = parseInt(e.currentTarget.dataset.value);
    let activeTab = parseInt(that.data.activeTab);
    let pileList = that.data.hospitalInfo.pileChairList;
    let pileStatusValue = that.data.chairPileStatusValue;
    that.data.tab0_event = e;
    console.log(value, activeTab, pileList, pileStatusValue)
    console.log("pileStatusValue-->", pileStatusValue, value);
    if (value == pileStatusValue) {
      that.clearRadio(activeTab, pileList)
    } else {
      let tempFilter = []
      for (let i = 0; i < pileList.length; i++) {
        tempFilter[i] = {}
        if (value == 1) { // 低电
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.lowPower == true)

        } else if (value == 2) { // 维护中
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.status == '维护中')
        } else if (value == 3) { // 待升级
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.versionIsNew == "old")
        } else if (value == 4) { //ble_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noBlueCount > 0)
        } else if (value == 5) { //归还rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noReadRFIDCount > 0)
        } else if (value == 14) { //租借rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.leaseNoReadRFIDCount > 0)
        } else if (value == 6) { //insert_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchNoCount > 0)
        } else if (value == 7) { //hook_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.hookStatNoCount > 0)
        } else if (value == 10) { //eject_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noEjectCount > 0)
        } else if (value == 8) { //omron
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchInfo == 'omron')
        } else if (value == 9) { //spring
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.spring == 'light_spring_steel_plate')
        } else if (value == 11) { //cap
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => !!item.reset)
        } else if (value == 12) { //losedChair
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.losedChairIds)
        } else if (value == 13) { //battery
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.batteryId == 0)
        } else if (value == 15) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.patroStatus == '待巡检')
        } else if (value == 16) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.motorQuesTimes > 0)
        }
        else if (value == 17) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.isneedChange == 0)
        }
        else if (value == 18) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.isOnline == 0)
        }
        else if (value == 20) { //近7日未巡检
            tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.dayIsInspect == 0)
          }
        tempFilter[i].location = pileList[i].location
      }

      that.setRadio('0', value, tempFilter)
    }
  },
  // 担架桩筛选
  pileCarChange: function (e) {
    let that = this
    console.log("pileCarChange-->", e);
    let value = parseInt(e.currentTarget.dataset.value);
    let activeTab = parseInt(that.data.activeTab);
    let pileList = that.data.hospitalInfo.pileStretchList;
    let pileStatusValue = that.data.carPileStatusValue;
    that.data.tab2_event = e;
    if (value == pileStatusValue) {
      that.clearRadio(activeTab, pileList)
    } else {
      let tempFilter = []
      for (let i = 0; i < pileList.length; i++) {
        tempFilter[i] = {}
        if (value == 1) { // 低电
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.lowPower == true)
        } else if (value == 2) { // 维护中
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.status == '维护中')
        } else if (value == 3) { // 待升级
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.versionIsNew == "old")
        } else if (value == 4) { //ble_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noBlueCount > 0)
        } else if (value == 5) { //归还rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noReadRFIDCount > 0)
        } else if (value == 14) { //租借rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.leaseNoReadRFIDCount > 0)
        } else if (value == 6) { //insert_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchNoCount > 0)
        } else if (value == 7) { //hook_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.hookStatNoCount > 0)
        } else if (value == 10) { //eject_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noEjectCount > 0)
        } else if (value == 8) { //omron
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchInfo == 'omron')
        } else if (value == 9) { //spring
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.spring == 'light_spring_steel_plate')
        } else if (value == 11) { //spring
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => !!item.reset)
        } else if (value == 13) { //battery
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.batteryId == 0)
        } else if (value == 20) { //近7日未巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.dayIsInspect == 0)
        }
        tempFilter[i].location = pileList[i].location
      }
      that.setRadio('2', value, tempFilter)
    }
  },
  // 轮椅筛选
  chairChange: function (e) {
    console.log("chairChange-->", e)
    let that = this
    let value = parseInt(e.currentTarget.dataset.value)
    let activeTab = parseInt(that.data.activeTab)
    let equipStatusValue = parseInt(that.data.chairStatusValue)
    let equipList = that.data.hospitalInfo.chairList
    that.data.tab1_event = e;
    if (value == equipStatusValue) {
      that.clearRadio(activeTab, equipList)
    } else {
      var equipListNew = []
      if (value == 7) { //本院到外院
        equipListNew = equipList.filter(item => !!item.backHospitalId && item.backHospitalId != that.data.hospitalId)
      } else if (value == 1) { //外院到本院
        equipListNew = equipList.filter(item => item.equHospitalId != that.data.hospitalId)
      } else if (value == 2) { //超过3天未租借
        equipListNew = equipList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
      } else if (value == 3) { //维护中
        equipListNew = equipList.filter(item => item.status == '维护中')
      } else if (value == 4) { //疑似丢失
        equipListNew = equipList.filter(item => item.status == '疑似丢失')
      } else if (value == 5) { //使用中
        equipListNew = equipList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
      } else if (value == 6) { //在桩上
        equipListNew = equipList.filter(item => item.status.indexOf('在桩上') != -1)
      } else if (value == 8) { //人工归还
        equipListNew = equipList.filter(item => item.status.indexOf('人工归还') != -1)
      } else if (value == 9) { //未支付赔偿
        equipListNew = equipList.filter(item => !!item.noPayOrder)
      } else if (value == 10) { //未巡检轮椅
        equipListNew = equipList.filter(item => item.patroStatus == 0)
        console.log(equipListNew, 'equipListNew')
      } else if (value == 20) { //近7日未巡检
        equipListNew = equipList.filter(item => item.dayIsInspect == 0)
      }
      that.setRadio("1", value, equipListNew)
    }
  },
   //其他设备筛选
   otherEquChange: function (e) {
    let that = this
    let value = parseInt(e.currentTarget.dataset.value)
    let activeTab = parseInt(that.data.activeTab)
    let equipStatusValue = parseInt(that.data.otherEquStatusValue)
    let equipList = that.data.hospitalInfo.otherEquList
    console.log("otherEquChange-->", value, activeTab, equipStatusValue, equipList)

    that.data.tab1_event = e;
    if (value == equipStatusValue) {
      that.clearRadio(activeTab, equipList)
    } else {
      var equipListNew = []
      if (value == 7) { //本院到外院
        equipListNew = equipList.filter(item => !!item.backHospitalId && item.backHospitalId != that.data.hospitalId)
      } else if (value == 1) { //外院到本院
        equipListNew = equipList.filter(item => item.equHospitalId != that.data.hospitalId)
      } else if (value == 2) { //超过3天未租借
        equipListNew = equipList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
      } else if (value == 3) { //维护中
        equipListNew = equipList.filter(item => item.status == '维护中')
      } else if (value == 4) { //疑似丢失
        equipListNew = equipList.filter(item => item.status == '疑似丢失')
      } else if (value == 5) { //使用中
        equipListNew = equipList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
      } else if (value == 6) { //在桩上
        equipListNew = equipList.filter(item => item.status.indexOf('在桩上') != -1)
      } else if (value == 8) { //人工归还
        equipListNew = equipList.filter(item => item.status.indexOf('人工归还') != -1)
      } else if (value == 9) { //未支付赔偿
        equipListNew = equipList.filter(item => !!item.noPayOrder)
      } else if (value == 10) { //未巡检轮椅
        equipListNew = equipList.filter(item => item.patroStatus == 0)
        console.log(equipListNew, 'equipListNew')
      } else if (value == 20) {
        equipListNew = equipList.filter(item => item.dayIsInspect == 0) 
      }
      that.setRadio("11", value, equipListNew)
    }
  },
  // 担架筛选
  carChange: function (e) {
    console.log("carChange-->", e)
    let that = this
    let value = parseInt(e.currentTarget.dataset.value)
    let activeTab = parseInt(that.data.activeTab);
    let equipStatusValue = parseInt(that.data.carStatusValue)
    let equipList = that.data.hospitalInfo.stretcherList
    that.data.tab3_event = e;
    if (value == equipStatusValue) {
      that.clearRadio(activeTab, equipList)
    } else {
      var equipListNew = []
      if (value == 7) { //本院到外院
        equipListNew = equipList.filter(item => !!item.backHospitalId && item.backHospitalId != that.data.hospitalId)
      } else if (value == 1) { //外院到本院
        equipListNew = equipList.filter(item => item.equHospitalId != that.data.hospitalId)
      } else if (value == 2) { //超过3天未租借
        equipListNew = equipList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
      } else if (value == 3) { //维护中
        equipListNew = equipList.filter(item => item.status == '维护中')
      } else if (value == 4) { //疑似丢失
        equipListNew = equipList.filter(item => item.status == '疑似丢失')
      } else if (value == 5) { //使用中
        equipListNew = equipList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
      } else if (value == 6) { //在桩上
        equipListNew = equipList.filter(item => item.status.indexOf('在桩上') != -1)
      } else if (value == 8) { //人工归还
        equipListNew = equipList.filter(item => item.status.indexOf('人工归还') != -1)
      } else if (value == 20) {
        equipListNew = equipList.filter(item => item.dayIsInspect == 0)  
      }
      that.setRadio("3", value, equipListNew)
    }
  },
   //其他桩筛选
   pileOtherChange: function (e) {
    let that = this
    console.log("pileOtherChange-->", e);
    let value = parseInt(e.currentTarget.dataset.value);
    let activeTab = parseInt(that.data.activeTab);
    let pileList = that.data.hospitalInfo.pileOtherList;
    let pileStatusValue = that.data.otherPileStatusValue;
    that.data.tab0_event = e;
    console.log(value, activeTab, pileList, pileStatusValue)
    console.log("pileStatusValue-->", pileStatusValue, value);
    if (value == pileStatusValue) {
      that.clearRadio(activeTab, pileList)
    } else {
      let tempFilter = []
      for (let i = 0; i < pileList.length; i++) {
        tempFilter[i] = {}
        if (value == 1) { // 低电
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.lowPower == true)

        } else if (value == 2) { // 维护中
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.status == '维护中')
        } else if (value == 3) { // 待升级
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.versionIsNew == "old")
        } else if (value == 4) { //ble_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noBlueCount > 0)
        } else if (value == 5) { //归还rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noReadRFIDCount > 0)
        } else if (value == 14) { //租借rfid_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.leaseNoReadRFIDCount > 0)
        } else if (value == 6) { //insert_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchNoCount > 0)
        } else if (value == 7) { //hook_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.hookStatNoCount > 0)
        } else if (value == 10) { //eject_err
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.noEjectCount > 0)
        } else if (value == 8) { //omron
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.switchInfo == 'omron')
        } else if (value == 9) { //spring
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.spring == 'light_spring_steel_plate')
        } else if (value == 11) { //cap
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => !!item.reset)
        } else if (value == 12) { //losedChair
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.losedChairIds)
        } else if (value == 13) { //battery
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.batteryId == 0)
        } else if (value == 15) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.patroStatus == '待巡检')
        } else if (value == 16) { //待巡检
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.motorQuesTimes > 0)
        } else if (value == 19) { //未上线
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.isOnline == 0)
        } else if (value == 20) {
          tempFilter[i].pileListList = pileList[i].pileListList.filter(item => item.dayIsInspect == 0)
        }
        tempFilter[i].location = pileList[i].location
      }
      console.log("------->selPileList---->", tempFilter);
      that.setRadio('10', value, tempFilter)
    }
  },
  patrolContinue: function () {
    let that = this
    that.getLocation(that.patrolContinueBack)
  },
  patrolEnd() {
    let that = this
    lbbService.patrolEnd({
      hospitalId: parseInt(that.data.hospitalId)
    }, function (res) {
      // if(!res.cancel){
      //   lbbService.patrolEnd({ hospitalId: parseInt(that.data.hospitalId),isForceOver:1 })
      // }
      that.setData({
        noIsShow: false,
        isShow: true
      })
      console.log("beginPolling>>", res)
      // let hospitalName = that.data.hospitalInfo.basicInfo.hospitalName
    })
  },
  patrolContinueBack: function () {
    let that = this
    wx.navigateTo({
      url: '/pages/startPatrol/startPatrol?hospitalId=' + that.data.hospitalId + '&hospitalName=' + that.data.hospitalInfo.basicInfo.hospitalName,
    })
  },
  showModal: function () {
    let that = this
    that.personalModal.showModal('确定开始巡检？', that.patrolStart)
  },
  patrolStart: function () {
    let that = this
    that.getLocation(function () {
      lbbService.startPatrol({
        hospitalId: parseInt(that.data.hospitalId)
      }, function (res) {
        console.log("beginPolling>>", res)
        let hospitalName = that.data.hospitalInfo.basicInfo.hospitalName
        that.setData({
          isShow: false,
          noIsShow: true
        })
        wx.navigateTo({
          url: '/pages/startPatrol/startPatrol?hospitalId=' + that.data.hospitalId + '&hospitalName=' + hospitalName,
        })
      })
    })
  },

  //新增桩位和设备的回调
  newEquip: function () {
    let that = this;
    that.data.isConnecting = false;
    let data = that.data.data_95;
    if (data) {
      let pileCode = that.data.pileCode
      let hospitalId = that.data.hospitalId
      let hospitalName = that.data.hospitalInfo.basicInfo.hospitalName
      let feeRules = JSON.stringify(that.data.hospitalInfo.basicInfo.feeRules)
      if (data.rfid.indexOf('FF') != -1) {
        wx.navigateTo({
          url: '/pages/newEquipment/newEquipment?hospitalId=' + hospitalId + '&hospitalName=' + hospitalName + '&pileCode=' + pileCode + '&feeRules=' + feeRules,
        })
      } else {
        lbbService.queryEquipByRfid({
          rfid: data.rfid
        }, function (res) {
          console.log("通过rfid获取到的信息>>", res)
          let equipCode = res.equipmentId
          let equipType = res.categoryName
          let eqtModelName = res.eqtModelName
          wx.navigateTo({
            url: '/pages/newEquipment/newEquipment?equipCode=' + equipCode + '&equipType=' + equipType + '&hospitalId=' + hospitalId + '&hospitalName=' + hospitalName + '&pileCode=' + pileCode + '&eqtModelName=' + eqtModelName + '&feeRules=' + feeRules,
          })
        })
      }
    }
  },
  //新增桩位和设备
  scan: function () {
    let that = this
    // wx.navigateTo({
    //   url: '/pages/newEquipment/newEquipment?hospitalId=' + that.data.hospitalId + '&hospitalName=' + that.data.hospitalInfo.basicInfo.hospitalName + '&pileCode=' + '11023' + '&feeRules=' + JSON.stringify(that.data.hospitalInfo.basicInfo.feeRules),
    // })
    that.getLocation(that.scanCallback)
  },
  scanCallback: function () {
    let that = this
    that.setData({
      isScanning: true
    })
    wx.scanCode({
      success(res) {
        var qrc = '';
        if (res.result.indexOf(util.CONST_DATA.DEVICE_QRCODE_URL_PREFIX) == 0) {
          var rst = res.result.split('/');
          qrc = rst[rst.length - 1];
          that.data.scan_qrc = qrc;
        } else {
          var str = res.result.split(':')
          var strn = ''
          str.forEach(item => {
            return strn += item
          })
          that.data.scan_qrc = strn;
        }
        that.data.isConnecting = true;
        lbbService.getMacId({
          markCode: that.data.scan_qrc,
          system: getApp().globalData.systemInfo ? getApp().globalData.systemInfo.system : 'ios'
        }, function (res) {
          if (res.macId) {
            that.data.newConFlg = res.newConFlg;
            that.data.curIsDirectCon = res.curIsDirectCon;
            that.data.pileCode = res.pileId;
            that.data.macId = res.macId;
            that.data.wxDeviceId = getApp().getDeviceId(res.macId);
            that.getConnect(res.macId);
          } else {
            that.data.isConnecting = false;
            that.toast.showToast('获取mac失败');
          }
        })
      },
      complete(res) {
        that.setData({
          isScanning: false
        })
      }
    })
  },
  onLoad: function (options) {
    let that = this
    console.log('options', options)
    console.log(app.globalData.config, 'app.globalData.config')
    that.setData({
      versionIsNew: options.versionIsNew,
      hospitalId: options.hospitalId,
      scrollHeight: app.getScrollHeight(45),
      cityId:options.cityId
    })
    that.getSignList(that.data.hospitalId)
  },
  onReady: function () {
    this.personalModal = this.selectComponent("#personalModal")
    this.toast = this.selectComponent("#toast")
  },
  onShow: function () {
    let that = this
    
    if (!that.data.isScanning) {
      lbbService.getHospitalDetail({
        hospitalId: parseInt(that.data.hospitalId)
      }, function (res) {
        console.log(res, 'detail')
        that.setData({
          hospitalInfo: res,
          pileChairListNew: res.pileChairList,
          pileStretchListNew: res.pileStretchList,
          chairListNew: res.chairList,
          carListNew: res.stretcherList,
          phcListNew: res.pileChaperonList,
          phcListChairNew: res.pileChaperonChairList,
          pileOtherNewList: res.pileOtherList,
          gatewayEquNewList: res.gatewayPileList,
          list: res.hospitalEquTyp,
        })

        wx.setNavigationBarTitle({
          title: that.data.hospitalInfo.basicInfo.hospitalName
        })
        that.getLength()
        that.getRoundIncompleteHosInfo()
        that.getProblemList()
        that.getProcessedNum()
        if (that.data.tab0_event) {
          that.setData({
            chairPileStatusValue: 0
          })
          that.pileChairChange(that.data.tab0_event)
        }
        if (that.data.tab1_event) {
          that.setData({
            chairStatusValue: 0
          })
          that.chairChange(that.data.tab1_event)
        }
        if (that.data.tab2_event) {
          that.setData({
            carPileStatusValue: 0
          })
          that.pileCarChange(that.data.tab2_event)
        }
        if (that.data.tab3_event) {
          that.setData({
            carStatusValue: 0
          })
          that.carChange(that.data.tab3_event)
        }
        if(that.data.tab10_event) {          
          that.setData({
            otherPileStatusValue: 0
          })
          that.pileOtherChange(that.data.tab10_event)
        }
        that.setOtherEquipmentList()
      })
    }
  },
  // 获取签到列表
  getSignList(hospitalId) {
    let that = this
    lbbService.getHospitalSignList({hospitalId:hospitalId},function(res){
        that.setData({
            infoTable:res.data
        })
    })
  }, 
  // 设备数组中转
  setOtherEquipmentList(equList) {
    console.log('我有没有执行')
    var that = this
    var arr = []
    var otherList = []
    var arrB
    let otherEquList = !equList ? that.data.hospitalInfo.otherEquList : equList;
    otherEquList.forEach((item) => {
      arr.push(item.equipName)
    })
    var arrA = new Set(arr)
    console.log(arrA)
    arrB = [...arrA]
    console.log('我有没有执行A', arrB)
    arrB.forEach((item) => {
      var list = []
      otherEquList.forEach((item1) => {
        if (item == item1.equipName) {
          list.push(item1)
        }
      })
      otherList.push({
        title: item,
        dataList: list
      })
    })
    that.setData({
      otherList: otherList
    })
    console.log('otherList:', otherList)
  },
  onHide: function () {
    // Do something when page hide.
    BLELocker.disconnect();
    this.hideModal1();
  },
  onUnload: function () {
    // Do something when page close.
  },
  hideModal1() {
    this.setData({
      modal: {
        modal_show: false,
        confirm: false,
        retry95: false,
        retryConnect: false
      }
    })
  },
  /**
   * 重试95
   */
  retry95() {
    let that = this;
    that.hideModal1();
    that.setData({
      loading_show: true,
      loading_desc: "数据读取中"
    });
    BLELocker.send95Command(function (isSuccess) {
      if (isSuccess == false) {
        that.getConnect(that.data.macId)
      } else { }
    })
  },
  /**
   * 重试蓝牙连接
   */
  retryConnect() {
    console.log('retryConnect');
    let that = this;
    that.hideModal1();
    that.getConnect(that.data.macId);
  },
  getConnect: function (macId) {
    let that = this
    that.setData({
      loading_show: true,
      loading_desc: "设备连接中"
    });
    if (that.data.newConFlg) {
      BLELocker.newConnect('DK' + macId, function (status, data) {
        blueConStatHandler.handleStatus(status, data, that, that.newEquip, true)
      }, 0, false, null, null, that);
    } else {
      BLELocker.directConnect('DK' + macId, function (status, data) {
        blueConStatHandler.handleStatus(status, data, that, that.newEquip, true)
      }, 0, false, null, null, that);
    }
  },
  getLocation: function (_callback) {
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log('获取经纬度成功', res)
        app.globalData.header.lat = parseFloat(res.latitude)
        app.globalData.header.lng = parseFloat(res.longitude)
        if (!app.globalData.header.lng) {
          wx.showToast({
            title: '请打开定位',
            image: '/images/gantan.png',
          })
          setTimeout(function () {
            wx.navigateTo({
              url: '/pages/toAuth/toAuth',
            })
            return
          }, 1000)
        } else if (_callback) {
          _callback()
        }
      },
      fail: function (res) {
        console.log('获取经纬度fail', res)
        wx.showToast({
          title: '请打开定位',
          image: '/images/gantan.png'
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '/pages/toAuth/toAuth',
          })
          return
        }, 1000)
      }
    })
  },
  getLength: function () {
    let that = this
    let phcCarNum = 0; //陪护床
    let pccNumber = 0; //陪护椅
    let pileCarNum = 0; //担架桩
    let pielphcCarNum = 0;
    //轮椅桩位
    let pileChairList = that.data.hospitalInfo.pileChairList
    let pileChairNum = 0; //轮椅桩
    let lowPowerArray_chair = []
    let maintainingArray_chair = []
    let lowVerArray_chair = []
    let bleErr_chair = []
    let rfidErr_chair = []
    let rent_rfidErr_chair = []
    let insertErr_chair = []
    let hookErr_chair = []
    let omron_chair = []
    let spring_chair = []
    let ejectErr_chair = []
    let cap_chair = []
    let losed_chair = []
    let battery_chair = []
    let notUnlock_chair = []
    let motorQuesTimes = []
    let ie_need_change=[]
    let noOnlineBox = []
    let sevenDay_NoInspected =[] 
    for (let i = 0; i < pileChairList.length; i++) {
      pileChairNum += pileChairList[i].pileListList.length
      lowPowerArray_chair = lowPowerArray_chair.concat(pileChairList[i].pileListList.filter(item => item.lowPower == true))
      maintainingArray_chair = maintainingArray_chair.concat(pileChairList[i].pileListList.filter(item => item.status == '维护中'))
      lowVerArray_chair = lowVerArray_chair.concat(pileChairList[i].pileListList.filter(item => item.versionIsNew == "old"))
      bleErr_chair = bleErr_chair.concat(pileChairList[i].pileListList.filter(item => item.noBlueCount > 0))
      rfidErr_chair = rfidErr_chair.concat(pileChairList[i].pileListList.filter(item => item.noReadRFIDCount > 0))
      rent_rfidErr_chair = rent_rfidErr_chair.concat(pileChairList[i].pileListList.filter(item => item.leaseNoReadRFIDCount > 0))
      insertErr_chair = insertErr_chair.concat(pileChairList[i].pileListList.filter(item => item.switchNoCount > 0))
      hookErr_chair = hookErr_chair.concat(pileChairList[i].pileListList.filter(item => item.hookStatNoCount > 0))
      ejectErr_chair = ejectErr_chair.concat(pileChairList[i].pileListList.filter(item => item.noEjectCount > 0))
      omron_chair = omron_chair.concat(pileChairList[i].pileListList.filter(item => item.switchInfo == 'omron'))
      spring_chair = spring_chair.concat(pileChairList[i].pileListList.filter(item => item.spring == "light_spring_steel_plate"))
      cap_chair = cap_chair.concat(pileChairList[i].pileListList.filter(item => !!item.reset))
      losed_chair = losed_chair.concat(pileChairList[i].pileListList.filter(item => item.losedChairIds))
      battery_chair = battery_chair.concat(pileChairList[i].pileListList.filter(item => item.batteryId == 0))
      notUnlock_chair = notUnlock_chair.concat(pileChairList[i].pileListList.filter(item => item.patroStatus == '待巡检')) // 增加未开锁巡检
      motorQuesTimes = motorQuesTimes.concat(pileChairList[i].pileListList.filter(item => item.motorQuesTimes > 0)) // 增加未开锁巡检
      ie_need_change=ie_need_change.concat(pileChairList[i].pileListList.filter(item => item.isneedChange == 0)) //需要更换电池
      noOnlineBox = noOnlineBox.concat(pileChairList[i].pileListList.filter(item => item.isOnline == 0))
      sevenDay_NoInspected = sevenDay_NoInspected.concat(pileChairList[i].pileListList.filter(item => item.dayIsInspect == 0)) //近7日未巡检
    }
    that.data.chairPileStatus.forEach(item => {
      if (item.value == 1) {
        item.num = lowPowerArray_chair.length;
      } else if (item.value == 2) {
        item.num = maintainingArray_chair.length;
      } else if (item.value == 3) {
        item.num = lowVerArray_chair.length;
      } else if (item.value == 4) {
        item.num = bleErr_chair.length;
      } else if (item.value == 5) {
        item.num = rfidErr_chair.length;
      } else if (item.value == 14) {
        item.num = rent_rfidErr_chair.length;
      } else if (item.value == 6) {
        item.num = insertErr_chair.length;
      } else if (item.value == 7) {
        item.num = hookErr_chair.length;
      } else if (item.value == 8) {
        item.num = omron_chair.length;
      } else if (item.value == 9) {
        item.num = spring_chair.length;
      } else if (item.value == 10) {
        item.num = ejectErr_chair.length;
      } else if (item.value == 11) {
        item.num = cap_chair.length;
      } else if (item.value == 12) {
        item.num = losed_chair.length;
      } else if (item.value == 13) {
        item.num = battery_chair.length;
      } else if (item.value == 15) {
        item.num = notUnlock_chair.length;
      } else if (item.value == 16) {
        item.num = motorQuesTimes.length;
      }
       else if (item.value == 17) {
        item.num = ie_need_change.length;
      }
      else if (item.value == 18) {
        item.num = noOnlineBox.length;
      }
      else if (item.value == 20) {
        item.num = sevenDay_NoInspected.length;
      }
    })
    that.setData({
      chairPileStatus: that.data.chairPileStatus,
      pileChairNum: pileChairNum
    })
    //担架桩位
    if (that.data.hospitalInfo.pileStretchList.length > 0) {
      let pileStretchList = that.data.hospitalInfo.pileStretchList
      let lowPowerArray_car = []
      let maintainingArray_car = []
      let lowVerArray_car = []
      let bleErr_car = []
      let rfidErr_car = []
      let rent_rfidErr_car = []
      let insertErr_car = []
      let hookErr_car = []
      let omron_car = []
      let spring_car = []
      let ejectErr_car = []
      let cap_car = []
      let battery_car = []
      let seven_day_no_Inspected = []
      for (let j = 0; j < pileStretchList.length; j++) {
        pileCarNum += pileStretchList[j].pileListList.length
        lowPowerArray_car = lowPowerArray_car.concat(pileStretchList[j].pileListList.filter(item => item.lowPower == true))
        maintainingArray_car = maintainingArray_car.concat(pileStretchList[j].pileListList.filter(item => item.status == '维护中'))
        lowVerArray_car = lowVerArray_car.concat(pileStretchList[j].pileListList.filter(item => item.versionIsNew == "old"))
        bleErr_car = bleErr_car.concat(pileStretchList[j].pileListList.filter(item => item.noBlueCount > 0))
        rfidErr_car = rfidErr_car.concat(pileStretchList[j].pileListList.filter(item => item.noReadRFIDCount > 0))
        rent_rfidErr_car = rent_rfidErr_car.concat(pileStretchList[j].pileListList.filter(item => item.leaseNoReadRFIDCount > 0))
        insertErr_car = insertErr_car.concat(pileStretchList[j].pileListList.filter(item => item.switchNoCount > 0))
        hookErr_car = hookErr_car.concat(pileStretchList[j].pileListList.filter(item => item.hookStatNoCount > 0))
        ejectErr_car = ejectErr_car.concat(pileStretchList[j].pileListList.filter(item => item.noEjectCount > 0))
        omron_car = omron_car.concat(pileStretchList[j].pileListList.filter(item => item.switchInfo == 'omron'))
        spring_car = spring_car.concat(pileStretchList[j].pileListList.filter(item => item.spring == "light_spring_steel_plate"))
        cap_car = cap_car.concat(pileStretchList[j].pileListList.filter(item => !!item.reset))
        battery_car = battery_car.concat(pileStretchList[j].pileListList.filter(item => item.batteryId == 0))
        seven_day_no_Inspected = seven_day_no_Inspected.concat(pileStretchList[j].pileListList.filter(item => item.dayIsInspect == 0))
      }
      that.data.carPileStatus.forEach(item => {
        if (item.value == 1) {
          item.num = lowPowerArray_car.length;
        } else if (item.value == 2) {
          item.num = maintainingArray_car.length;
        } else if (item.value == 3) {
          item.num = lowVerArray_car.length;
        } else if (item.value == 4) {
          item.num = bleErr_car.length;
        } else if (item.value == 5) {
          item.num = rfidErr_car.length;
        } else if (item.value == 14) {
          item.num = rent_rfidErr_car.length;
        } else if (item.value == 6) {
          item.num = insertErr_car.length;
        } else if (item.value == 7) {
          item.num = hookErr_car.length;
        } else if (item.value == 8) {
          item.num = omron_car.length;
        } else if (item.value == 9) {
          item.num = spring_car.length;
        } else if (item.value == 10) {
          item.num = ejectErr_car.length;
        } else if (item.value == 11) {
          item.num = cap_car.length;
        } else if (item.value == 13) {
          item.num = battery_car.length;
        } else if (item.value == 20) {
            item.num = seven_day_no_Inspected.length
        }
      })
      that.setData({
        carPileStatus: that.data.carPileStatus,
        pileCarNum: pileCarNum
      })
    }
    //陪护床桩位
    if (that.data.hospitalInfo.pileChaperonList.length > 0) {
      let pileChaperonList = that.data.hospitalInfo.pileChaperonList
      pileChaperonList.forEach(item => {
        phcCarNum += item.pileListList.length;
      })
      that.setData({
        phcCarNum: phcCarNum
      })
    }
    //陪护床桩位
    if (that.data.hospitalInfo.pileChaperonChairList.length > 0) {
      let pileChaperonChairList = that.data.hospitalInfo.pileChaperonChairList
      pileChaperonChairList.forEach(item => {
        pccNumber += item.pileListList.length;
      })
      that.setData({
        pccNumber: pccNumber
      })
    }
    //桩位数量
    if (that.data.hospitalInfo.pileOtherList.length > 0) {

      //其他桩位
      let pileOtherList = that.data.hospitalInfo.pileOtherList
      let pileChairNum = 0; //轮椅桩
      let lowPowerArray_chair = []
      let maintainingArray_chair = []
      let lowVerArray_chair = []
      let bleErr_chair = []
      let rfidErr_chair = []
      let rent_rfidErr_chair = []
      let insertErr_chair = []
      let hookErr_chair = []
      let omron_chair = []
      let spring_chair = []
      let ejectErr_chair = []
      let cap_chair = []
      let losed_chair = []
      let battery_chair = []
      let notUnlock_chair = []
      let motorQuesTimes = []
      let nb48NoOnline = []
      let fiveDayRetryOnline = []
      let noOnlineBox = []
      let s_d_n_i = []
      for (let i = 0; i < pileOtherList.length; i++) {
        pileChairNum += pileOtherList[i].pileListList.length
        lowPowerArray_chair = lowPowerArray_chair.concat(pileOtherList[i].pileListList.filter(item => item.lowPower == true))
        maintainingArray_chair = maintainingArray_chair.concat(pileOtherList[i].pileListList.filter(item => item.status == '维护中'))
        lowVerArray_chair = lowVerArray_chair.concat(pileOtherList[i].pileListList.filter(item => item.versionIsNew == "old"))
        bleErr_chair = bleErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.noBlueCount > 0))
        rfidErr_chair = rfidErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.noReadRFIDCount > 0))
        rent_rfidErr_chair = rent_rfidErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.leaseNoReadRFIDCount > 0))
        insertErr_chair = insertErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.switchNoCount > 0))
        hookErr_chair = hookErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.hookStatNoCount > 0))
        ejectErr_chair = ejectErr_chair.concat(pileOtherList[i].pileListList.filter(item => item.noEjectCount > 0))
        omron_chair = omron_chair.concat(pileOtherList[i].pileListList.filter(item => item.switchInfo == 'omron'))
        spring_chair = spring_chair.concat(pileOtherList[i].pileListList.filter(item => item.spring == "light_spring_steel_plate"))
        cap_chair = cap_chair.concat(pileOtherList[i].pileListList.filter(item => !!item.reset))
        losed_chair = losed_chair.concat(pileOtherList[i].pileListList.filter(item => item.losedChairIds))
        battery_chair = battery_chair.concat(pileOtherList[i].pileListList.filter(item => item.batteryId == 0))
        notUnlock_chair = notUnlock_chair.concat(pileOtherList[i].pileListList.filter(item => item.patroStatus == '待巡检')) // 增加未开锁巡检
        motorQuesTimes = motorQuesTimes.concat(pileOtherList[i].pileListList.filter(item => item.motorQuesTimes > 0)) // 增加未开锁巡检
        nb48NoOnline = nb48NoOnline.concat(pileOtherList[i].pileListList.filter(item=> item.nb48HnoOnline > 0)); //48小时未上线
        fiveDayRetryOnline = fiveDayRetryOnline.concat(pileOtherList[i].pileListList.filter(item=> item.fiveDayRetryOnline > 0));//五天重试上线
        noOnlineBox = noOnlineBox.concat(pileOtherList[i].pileListList.filter(item=> item.isOnline == 0))
        s_d_n_i = s_d_n_i.concat(pileOtherList[i].pileListList.filter(item=> item.dayIsInspect == 0))
      }
      that.data.otherPileStatus.forEach(item => {
        if (item.value == 1) {
          item.num = lowPowerArray_chair.length;
        } else if (item.value == 2) {
          item.num = maintainingArray_chair.length;
        } else if (item.value == 3) {
          item.num = lowVerArray_chair.length;
        } else if (item.value == 4) {
          item.num = bleErr_chair.length;
        } else if (item.value == 5) {
          item.num = rfidErr_chair.length;
        } else if (item.value == 14) {
          item.num = rent_rfidErr_chair.length;
        } else if (item.value == 6) {
          item.num = insertErr_chair.length;
        } else if (item.value == 7) {
          item.num = hookErr_chair.length;
        } else if (item.value == 8) {
          item.num = omron_chair.length;
        } else if (item.value == 9) {
          item.num = spring_chair.length;
        } else if (item.value == 10) {
          item.num = ejectErr_chair.length;
        } else if (item.value == 11) {
          item.num = cap_chair.length;
        } else if (item.value == 12) {
          item.num = losed_chair.length;
        } else if (item.value == 13) {
          item.num = battery_chair.length;
        } else if (item.value == 15) {
          item.num = notUnlock_chair.length;
        } else if (item.value == 16) {
          item.num = motorQuesTimes.length;
        } else if(item.value == 17) {
          item.num = nb48NoOnline.length;
        } else if(item.value == 18) {
          item.num = fiveDayRetryOnline.length;
        } else if(item.value == 19) {
          item.num = noOnlineBox.length;
        } else if(item.value == 20) {
           item.num =  s_d_n_i.length
        }
      })
      that.setData({
        otherPileStatus: that.data.otherPileStatus,
        pielphcCarNum: pileChairNum,
        pileOtherNewList:pileOtherList
      })
     
    }
    //轮椅
    let chairList = that.data.hospitalInfo.chairList
    let noRentChair = chairList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
    let maintainingChair = chairList.filter(item => item.status == '维护中')
    let mayLostChair = chairList.filter(item => item.status == '疑似丢失')
    let usingChair = chairList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
    let inPileChair = chairList.filter(item => item.status.indexOf('在桩上') != -1)
    let outChair = chairList.filter(item => !!item.backHospitalId && item.backHospitalId != that.data.hospitalId)
    let inChair = chairList.filter(item => item.equHospitalId != that.data.hospitalId) //外院到本院
    let manBack = chairList.filter(item => item.status.indexOf('人工归还') != -1)
    let noPaid = chairList.filter(item => !!item.noPayOrder)
    let NoInspection = chairList.filter(item => item.patroStatus == 0) //待巡检
    let seven_day_noInspected = chairList.filter(item => item.dayIsInspect == 0) //近7日未巡检
    that.data.chairStatus[0].num = outChair.length
    that.data.chairStatus[1].num = noRentChair.length
    that.data.chairStatus[2].num = maintainingChair.length
    that.data.chairStatus[3].num = inChair.length
    that.data.chairStatus[4].num = mayLostChair.length
    that.data.chairStatus[5].num = usingChair.length
    that.data.chairStatus[6].num = inPileChair.length
    that.data.chairStatus[7].num = manBack.length
    that.data.chairStatus[8].num = noPaid.length
    that.data.chairStatus[9].num = NoInspection.length
    that.data.chairStatus[10].num = seven_day_noInspected.length
    that.setData({
      chairStatus: that.data.chairStatus
    })
    //担架
    if (that.data.hospitalInfo.stretcherList.length > 0) {
      let stretcherList = that.data.hospitalInfo.stretcherList
      let noRentCar = stretcherList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
      let maintainingCar = stretcherList.filter(item => item.status == '维护中')
      let mayLostCar = stretcherList.filter(item => item.status == '疑似丢失')
      let usingCar = stretcherList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
      let inPileCar = stretcherList.filter(item => item.status.indexOf('在桩上') != -1)
      let seven_day_no_inspected = stretcherList.filter(item => item.dayIsInspect == 0)
      that.data.carStatus[0].num = noRentCar.length
      that.data.carStatus[1].num = maintainingCar.length
      that.data.carStatus[2].num = mayLostCar.length
      that.data.carStatus[3].num = usingCar.length
      that.data.carStatus[4].num = inPileCar.length
      
      that.data.carStatus[6].num = seven_day_no_inspected.length
      that.setData({
        carStatus: that.data.carStatus
      })
    }


    //其他设备
    let otherEquList = that.data.hospitalInfo.otherEquList
    console.log("optherEquList->", otherEquList);
    let otherNoRentChair = otherEquList.filter(item => item.status != '疑似丢失' && item.backTime && (new Date().getTime() - (new Date(item.backTime.replace(new RegExp("-", "gm"), "/"))).getTime()) > 259200000)
    let otherMaintainingChair = otherEquList.filter(item => item.status == '维护中')
    let otherMayLostChair = otherEquList.filter(item => item.status == '疑似丢失')
    let otherUsingChair = otherEquList.filter(item => item.status.indexOf('使用中') != -1 || item.status.indexOf('月租') != -1)
    let otherInPileChair = otherEquList.filter(item => item.status.indexOf('在桩上') != -1)
    let otherOutChair = otherEquList.filter(item => !!item.backHospitalId && item.backHospitalId != that.data.hospitalId)
    let otherInChair = otherEquList.filter(item => item.equHospitalId != that.data.hospitalId) //外院到本院
    let otherManBack = otherEquList.filter(item => item.status.indexOf('人工归还') != -1)
    let otherNoPaid = otherEquList.filter(item => !!item.noPayOrder)
    let otherNoInspection = otherEquList.filter(item => item.patroStatus == 0) //待巡检
    let seven_day_no_inspected_list = otherEquList.filter(item => item.dayIsInspect == 0) //近7日巡检

    that.data.otherEquStatus[0].num = otherOutChair.length
    that.data.otherEquStatus[1].num = otherNoRentChair.length
    that.data.otherEquStatus[2].num = otherMaintainingChair.length
    that.data.otherEquStatus[3].num = otherInChair.length
    that.data.otherEquStatus[4].num = otherMayLostChair.length
    that.data.otherEquStatus[5].num = otherUsingChair.length
    that.data.otherEquStatus[6].num = otherInPileChair.length
    that.data.otherEquStatus[7].num = otherManBack.length
    that.data.otherEquStatus[8].num = otherNoPaid.length
    that.data.otherEquStatus[9].num = otherNoInspection.length
    that.data.otherEquStatus[10].num = seven_day_no_inspected_list.length
    console.log("otherEquStatus-->",that.data.otherEquStatus)
    that.setData({
      otherEquStatus: that.data.otherEquStatus
    })


    if (pileChairNum == 0) {
      if(that.data.pileCarNum > 0) {
        that.setData({
          activeTab: 2
        })
      }else if(that.data.phcCarNum > 0) {
        that.setData({
          activeTab: 6
        })
      }else if(that.data.pccNumber > 0) {
        that.setData({
          activeTab: 7
        })
      }else if(that.data.pielphcCarNum > 0) {
        that.setData({
          activeTab: 10
        })
      }else if (that.data.hospitalInfo.chairList.length > 0) {
        that.setData({
          activeTab: 1
        })
      }else if (that.data.hospitalInfo.stretcherList.length > 0) {
        that.setData({
          activeTab: 3
        })  
      }      
      
    }

    console.log("----activeTab=", that.data.activeTab);
  },

  resetRadio: function () {
    let that = this
    that.setData({
      chairPileStatus: [{
        value: '1',
        name: '低电桩',
        checked: false,
        color: 'color-r'
      },
      {
        value: '2',
        name: '维护中',
        checked: false,
        color: 'color-r'
      },
      {
        value: '4',
        name: '蓝牙连不上',
        checked: false,
        color: 'color-r'
      },
      {
        value: '14',
        name: '租借rfid不识别',
        checked: false,
        color: 'color-r'
      },
      {
        value: '5',
        name: '归还rfid不识别',
        checked: false,
        color: 'color-r'
      },
      {
        value: '6',
        name: '插入开关',
        checked: false,
        color: 'color-r'
      },
      {
        value: '7',
        name: '锁钩开关',
        checked: false,
        color: 'color-r'
      },
      {
        value: '10',
        name: '弹不开',
        checked: false,
        color: 'color-r'
      },
      {
        value: '12',
        name: '丢轮椅',
        checked: false,
        color: 'color-b'
      },
      {
        value: '3',
        name: '待升级',
        checked: false,
        color: 'color-r'
      },
      {
        value: '13',
        name: '待换锂电池',
        checked: false,
        color: 'color-b'
      },
      {
        value: '8',
        name: '欧姆龙开关',
        checked: false,
        color: 'color-b'
      },
      {
        value: '9',
        name: '轻弹簧',
        checked: false,
        color: 'color-b'
      },
      {
        value: '11',
        name: '复位电容',
        checked: false,
        color: 'color-b'
      },
      {
        value: '15',
        name: '未开锁巡检',
        checked: false,
        color: 'color-r'
      }
      ],
      chairPileStatusValue: 0,
      carPileStatus: [{
        value: '1',
        name: '低电桩',
        checked: false,
        color: 'color-r'
      },
      {
        value: '2',
        name: '维护中',
        checked: false,
        color: 'color-r'
      },
      {
        value: '4',
        name: '蓝牙连不上',
        checked: false,
        color: 'color-r'
      },
      {
        value: '14',
        name: '租借rfid不识别',
        checked: false,
        color: 'color-r'
      },
      {
        value: '5',
        name: '归还rfid不识别',
        checked: false,
        color: 'color-r'
      },
      {
        value: '6',
        name: '插入开关',
        checked: false,
        color: 'color-r'
      },
      {
        value: '7',
        name: '锁钩开关',
        checked: false,
        color: 'color-r'
      },
      {
        value: '10',
        name: '弹不开',
        checked: false,
        color: 'color-r'
      },
      {
        value: '3',
        name: '待升级',
        checked: false,
        color: 'color-r'
      },
      {
        value: '13',
        name: '待换锂电池',
        checked: false,
        color: 'color-b'
      },
      {
        value: '8',
        name: '欧姆龙开关',
        checked: false,
        color: 'color-b'
      },
      {
        value: '9',
        name: '轻弹簧',
        checked: false,
        color: 'color-b'
      },
      {
        value: '11',
        name: '复位电容',
        checked: false,
        color: 'color-b'
      },
      {
        value: '15',
        name: '未开锁巡检',
        checked: false,
        color: 'color-r'
      },
      ],
      carPileStatusValue: 0,
      chairStatus: [{
        value: '7',
        name: '本院到外院',
        checked: false
      },
      {
        value: '2',
        name: '3天未租借',
        checked: false
      },
      {
        value: '3',
        name: '维护中',
        checked: false
      },
      {
        value: '1',
        name: '外院到本院',
        checked: false
      },
      {
        value: '4',
        name: '疑似丢失',
        checked: false
      },
      {
        value: '5',
        name: '使用中',
        checked: false
      },
      {
        value: '6',
        name: '在桩上',
        checked: false
      },
      {
        value: '8',
        name: '人工归还',
        checked: false
      },
      {
        value: '9',
        name: '未支付赔偿',
        checked: false
      },
      {
        value: '9',
        name: '未巡检轮椅',
        checked: false
      },
      ],
      chairStatusValue: 0,
      carStatus: [
        {
          value: '2',
          name: '3天未租借',
          checked: false
        },
        {
          value: '3',
          name: '维护中',
          checked: false
        },
        {
          value: '4',
          name: '疑似丢失',
          checked: false
        },
        {
          value: '5',
          name: '使用中',
          checked: false
        },
        {
          value: '6',
          name: '在桩上',
          checked: false
        },
        
      ],
      carStatusValue: 0,
    })
  },
  toMap() {
    var that = this
    wx.navigateTo({
      url: '/pages/hospitalMap/hospitalMap?hospitalId=' + that.data.hospitalId + '&sameCityHosLatLng=' + JSON.stringify(that.data.hospitalInfo.basicInfo.sameCityHosLatLng),
    })
  },
  toMapThisHospital() {
    var that = this
    var arr = [{
      lat: that.data.hospitalInfo.basicInfo.lbmLat,
      lng: that.data.hospitalInfo.basicInfo.lbmLng,
      lbmName: that.data.hospitalInfo.basicInfo.hospitalName,
      lbmId: that.data.hospitalId,
    }]
    that.data.hospitalInfo.basicInfo.positionInfos.forEach((item) => {
      arr.push({
        lat: item.lat,
        lng: item.lng,
        lbmName: item.lbmName,
        lbmId: item.lbmId,
      })
    })
    console.log(arr, 'arrrr')
    wx.navigateTo({
      url: '/pages/hospitalMap/hospitalMap?hospitalId=' + that.data.hospitalId + '&sameCityHosLatLng=' + JSON.stringify(arr)
    })
  },
  //去待处理医院
  toPendingHospital(){
    wx.navigateTo({
        url: '/pkgTask/pages/pendingHospital/index?cityId='+this.data.cityId
      })  
  },
  //去运维任务医院详情
 async toMaintenanceTask(){
      let that=this
      let userId=''
      let year=new Date().getFullYear()
      let month=new Date().getMonth()+1
    //  await lbbService.getWorker({
    //     taskType: 0
    // }, function (res) {
    //     userId=res.data[0].id
    // })
    wx.navigateTo({
        url: '/pkgTask/pages/handleTask/handleTask?hospitalId='+that.data.hospitalId+'&taskType=0'+'&userId='+userId+'&time='+year+'-'+month+'&hospitalName='+ that.data.hospitalInfo.basicInfo.hospitalName
      })  
  },
  // toMapThisHospitalDetail(){
  //   var that = this
  //   wx.navigateTo({
  //     url: '../hospitalMap/hospitalMap?hospitalId='+that.data.hospitalId+'&sameCityHosLatLng='+JSON.stringify(that.data.hospitalInfo.basicInfo.positionInfos),
  //   })
  // }
  onPageScroll(e) {
    console.log(e)
  },
  // 跳转到对应的标签详情内容区
  toDetail(e) {
    console.log(e, this)
    this.setData({
      storeDetail: e.currentTarget.dataset.id
    })
  },
  //判断有无问题统计
  getProblemList(){
    let that=this
    lbbService.getIncompleteProNum({ hospitalId: parseInt(that.data.hospitalId) },function(res){
        if(res.data>0){
            that.setData({
                problemColor:1
            })
        }else{
            that.setData({
                problemColor:0
            })  
        }
        console.log(666,res)
      })
  },
  //判断有无未巡检已处理
  getProcessedNum(){
      let that=this
    lbbService.getAllPartsDepreciationNum({hospitalId: parseInt(that.data.hospitalId)},function (res) {
        that.setData({
            unInspectEquHandleNum:res.data.unInspectEquHandleNum,
            unInspectPileHandleNum:res.data.unInspectPileHandleNum,
            incompleteTaskNum:res.data.incompleteTaskNum
         }) 
      })
  },
  //判断当前城市有无待处理医院
  getRoundIncompleteHosInfo(){
      let that =this
      lbbService.getRoundIncompleteHosInfo({
        pageNo:1,
        pageSize:10,
        cityId:that.data.cityId
      },function(res) {
        if(res.data.records&&res.data.records?.length>0){
            that.setData({
                ifShowUntreated:true
            })
        } else{
            that.setData({
                ifShowUntreated:false
            })
        } 
      })
  },
  setMaintenance(e) {
    let  that = this
    wx.showModal({
      title: '提示',
      content: '是否将该位置的桩位全部设置成维护中',
      complete: (res) => {
        if (res.cancel) {
          return
        }
    
        if (res.confirm) {
            console.log('----------------------->',e)
            lbbService.updateBatchPileStat({lbmid:this.data.hospitalId,position:e.currentTarget.dataset.location,nowStat:3,equType:that.data.activeTab==0 ? 1 : that.data.activeTab==2 ? 2 :''},function(res){
                if (!that.data.isScanning) {
                    lbbService.getHospitalDetail({
                      hospitalId: parseInt(that.data.hospitalId)
                    }, function (res) {
                      console.log(res, 'detail')
                      that.setData({
                        hospitalInfo: res,
                        pileChairListNew: res.pileChairList,
                        pileStretchListNew: res.pileStretchList,
                        chairListNew: res.chairList,
                        carListNew: res.stretcherList,
                        phcListNew: res.pileChaperonList,
                        phcListChairNew: res.pileChaperonChairList,
                        pileOtherNewList: res.pileOtherList,
                        gatewayEquNewList: res.gatewayPileList,
                        list: res.hospitalEquTyp,
                      })
              
                      wx.setNavigationBarTitle({
                        title: that.data.hospitalInfo.basicInfo.hospitalName
                      })
                      that.getLength()
                      that.getRoundIncompleteHosInfo()
                      that.getProblemList()
                      that.getProcessedNum()
                      if (that.data.tab0_event) {
                        that.setData({
                          chairPileStatusValue: 0
                        })
                        that.pileChairChange(that.data.tab0_event)
                      }
                      if (that.data.tab1_event) {
                        that.setData({
                          chairStatusValue: 0
                        })
                        that.chairChange(that.data.tab1_event)
                      }
                      if (that.data.tab2_event) {
                        that.setData({
                          carPileStatusValue: 0
                        })
                        that.pileCarChange(that.data.tab2_event)
                      }
                      if (that.data.tab3_event) {
                        that.setData({
                          carStatusValue: 0
                        })
                        that.carChange(that.data.tab3_event)
                      }
                      if(that.data.tab10_event) {          
                        that.setData({
                          otherPileStatusValue: 0
                        })
                        that.pileOtherChange(that.data.tab10_event)
                      }
                      that.setOtherEquipmentList()
                    })
                  }
            })
        }
      }
    })
  },
  setNormal(e) {
    let  that = this
    wx.showModal({
        title: '提示',
        content: '是否将该位置的桩位全部设置成正常',
        complete: (res) => {
          if (res.cancel) {
            return
          }
      
          if (res.confirm) {
            lbbService.updateBatchPileStat({lbmid:this.data.hospitalId,position:e.currentTarget.dataset.location,nowStat:1,equType:that.data.activeTab==0 ? 1 : that.data.activeTab==2 ? 2 :''},function(res){
                if (!that.data.isScanning) {
                    lbbService.getHospitalDetail({
                      hospitalId: parseInt(that.data.hospitalId)
                    }, function (res) {
                      console.log(res, 'detail')
                      that.setData({
                        hospitalInfo: res,
                        pileChairListNew: res.pileChairList,
                        pileStretchListNew: res.pileStretchList,
                        chairListNew: res.chairList,
                        carListNew: res.stretcherList,
                        phcListNew: res.pileChaperonList,
                        phcListChairNew: res.pileChaperonChairList,
                        pileOtherNewList: res.pileOtherList,
                        gatewayEquNewList: res.gatewayPileList,
                        list: res.hospitalEquTyp,
                      })
              
                      wx.setNavigationBarTitle({
                        title: that.data.hospitalInfo.basicInfo.hospitalName
                      })
                      that.getLength()
                      that.getRoundIncompleteHosInfo()
                      that.getProblemList()
                      that.getProcessedNum()
                      if (that.data.tab0_event) {
                        that.setData({
                          chairPileStatusValue: 0
                        })
                        that.pileChairChange(that.data.tab0_event)
                      }
                      if (that.data.tab1_event) {
                        that.setData({
                          chairStatusValue: 0
                        })
                        that.chairChange(that.data.tab1_event)
                      }
                      if (that.data.tab2_event) {
                        that.setData({
                          carPileStatusValue: 0
                        })
                        that.pileCarChange(that.data.tab2_event)
                      }
                      if (that.data.tab3_event) {
                        that.setData({
                          carStatusValue: 0
                        })
                        that.carChange(that.data.tab3_event)
                      }
                      if(that.data.tab10_event) {          
                        that.setData({
                          otherPileStatusValue: 0
                        })
                        that.pileOtherChange(that.data.tab10_event)
                      }
                      that.setOtherEquipmentList()
                    })
                  }
            })
          }
        }
      })
  }
})